<template>
  <div>
    <div class="login">
      <div class="login-header">
        <div class="header-left">
          <a title="淘宝网" href="https://world.taobao.com/"></a>
        </div>
        <div class="header-right">
          <a title="淘宝网" href="">网站无障碍</a>
          <a href="">
            <sicon type="3.1 评论" color="red" size="24"></sicon>
            <span>"登录页面*""改进建议"</span>
          </a>
        </div>
      </div>
      <div class="login-main">
        <div class="main-box">
          <div class="box-personal">
            <div class="personal-tab">
              <div>密码登录</div>
            </div>
            <Form
              class="personal-user"
              :validation-schema="schema"
              @submit="onSubmit(userInfo.phone, userInfo.password)"
            >
              <div class="user-item">
                <sicon class="item-icon" type="3.1我的" size="40"></sicon>
                <Field
                  v-model="userInfo.phone"
                  name="phoneFn"
                  type="text"
                  placeholder="账号名/邮箱/手机号"
                />
                <ErrorMessage class="error-msg" name="phoneFn" />
              </div>

              <div class="user-item">
                <sicon class="item-icon" type="密码" size="40"></sicon>
                <Field
                  name="passwordFn"
                  v-model="userInfo.password"
                  type="password"
                  placeholder="请输入登录密码"
                />
                <ErrorMessage class="error-msg" name="passwordFn" />
              </div>

              <div class="user-item">
                <div class="item-btns">
                  <button>登录</button>
                  <button @click="toRegister">注册账号</button>
                </div>
              </div>
            </Form>
          </div>
        </div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="footer">
      <div class="footer-copy-main">
        <div class="footer-copy-area">
          <div class="footer-nav">
            <a href="#">关于天猫</a>
            <a href="#">帮助中心</a>
            <a href="#">开放平台</a>
            <a href="#">诚聘英才</a>
            <a href="#">联系我们</a>
            <a href="#">网站合作</a>
            <a href="#">法律声明</a>
            <a href="#">隐私权政策</a>
            <a href="#">知识产权</a>
            <a href="#">廉正举报</a>
            <a href="#">规则意见征集</a>
          </div>
          <div class="friend-link">
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
            <span>|</span>
            <a href="#">阿里巴巴集团</a>
          </div>
          <ul class="footer-cert">
            <li>增值电信业务经营许可证： <a href="#">浙B2-20110446</a></li>
            <li>网络文化经营许可证：<a href="#">浙网文[2015]0295-065号</a></li>
            <li><a href="#">12318举报</a></li>
            <li>
              互联网违法和不良信息举报电话：0571-81683755 blxxjb@alibaba-inc.com
            </li>
            <li>
              互联网药品信息服务资质证书编号：<a href="#"
                >浙-（经营性）-2017-0005</a
              >
            </li>
            <li>
              <img
                src="@/components/footer/images/cert_icon.png"
                alt="浙公网"
                style="vertical-align: middle"
              />&nbsp;<a href="#">浙公网安备 33010002000120号</a>
            </li>
          </ul>
          <div class="copy">© 2003-2018 TMALL.COM 版权所有</div>
          <div class="cert-logo">
            <a href="#" class="cert-logo-list"
              ><img src="@/components/footer/images/cert_logo1.jpg" alt=""
            /></a>
            <a href="#" class="cert-logo-list"
              ><img src="@/components/footer/images/cert_logo2.jpg" alt=""
            /></a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "ShopLogin",
};
</script>

<script lang="ts" setup>
import { Form, Field, ErrorMessage } from "vee-validate";
import { phoneReg, passwordReg } from "@/utils/rules";
import { reactive } from "vue";
import { useUserInfoStore } from "@/stores/user";
import { useRouter, useRoute } from "vue-router";
const userInfoStore = useUserInfoStore();
const router = useRouter();
const route = useRoute();

const toRegister = () => {
  router.push({
    name: "Register"
  })
}

const userInfo = reactive({
  phone: "",
  password: "",
});

const schema = {
  phoneFn(value) {
    if (!value) return "手机号不能为空";
    if (!phoneReg.test(value)) return "请填写正确的手机号";
    return true;
  },
  passwordFn(value) {
    if (!value) return "密码必填";
    if (!passwordReg.test(value)) return "请填写正确的密码";
    return true;
  },
};
const onSubmit = async () => {
  await userInfoStore.login(userInfo);
  router.replace(route.query.redirect || "/home");
};
</script>

<style lang="less" scoped>
.login a {
  text-decoration: none;
  color: #999999;
}
.login a:hover {
  color: #fa3b3b;
}
.login {
  .login-header {
    min-width: 1200px;
    width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    padding: 22px 0;
    .header-left {
      a {
        display: block;
        height: 45px;
        width: 72px;
        background: url("@/assets/login_imges/下载.png") no-repeat 0 0/100% 100%;
      }
    }
    .header-right {
      display: flex;
      flex-direction: column;
      a {
        line-height: 24px;
        &:last-child {
          display: flex;
          align-items: center;
        }
      }
    }
  }
  .login-main {
    background: url("https://gw.alicdn.com/imgextra/i3/O1CN01iyYdem1GQd1yGgA0a_!!6000000000617-0-tps-2500-600.jpg");
    background-size: 100% 100%;
    // min-height: 600px;
    height: calc(100vh - 292px);
    min-width: 1200px;
    background-position: center;
    background-repeat: no-repeat;
    .main-box {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      width: 1200px;
      margin: 0 auto;
      height: 100%;
      .box-personal {
        padding: 25px 25px 23px;
        width: 350px;
        background-color: hsla(0, 0%, 100%, 0.9);
        .personal-tab {
          display: flex;
          margin-bottom: 20px;
          margin-top: 4px;
          justify-content: center;
          div {
            height: 20px;
            line-height: 1px;
            font-size: 25px;
            color: #3c3c3c;
            margin: 9px 10px 0 0;
            font-weight: 700;
            border-bottom: 2px solid #000;
          }
        }
        .personal-user {
          display: flex;
          flex-direction: column;
          .user-item {
            margin-bottom: 25px;
            display: flex;
            font-size: 20px;
            position: relative;
            .item-icon {
              background-color: #cccccc;
              color: #fff;
              padding: 10px;
            }
            input {
              height: 60px;
              line-height: 60px;
              width: 100%;
              text-align: center;
            }
            .item-btns {
              width: 100%;
              display: flex;
              justify-content: space-between;
              button {
                width: 40%;
                padding: 10px 0;
                border: none;
                border-radius: 5px;
                background-color: #ff4400;
                color: #fff;
              }
            }
          }
        }
      }
    }
  }
}

// 底部样式
.footer {
  width: 100%;
  height: auto;
  clear: both;
}

.footer .footer-copy-main {
  width: 100%;
  height: 200px;
  clear: both;
  background: #fff;
}
.footer .footer-copy-area {
  width: 1230px;
  height: 100%;
  margin: 0 auto;
}
.footer .footer-nav {
  width: 100%;
  height: auto;
  padding-top: 8px;
}
.footer .footer-nav a,
.footer .friend-link a {
  color: #a4a4a4;
  font-size: 12px;
  text-decoration: none;
}
.footer .friend-link {
  width: 100%;
  height: auto;
  margin-top: 18px;
}
.footer .friend-link span {
  color: #ffffff;
  font-size: 12px;
}
.footer .footer-cert {
  width: 100%;
  height: auto;
  font-size: 12px;
  color: #a4a4a4;
  margin-top: 10px;
}
.footer .footer-cert li {
  float: left;
  width: auto;
  height: auto;
  height: 25px;
  overflow: hidden;
  margin-right: 7%;
}
.footer .footer-cert li:nth-child(4) {
  margin-right: 0px;
}
.footer .footer-cert a {
  color: #a4a4a4;
  text-decoration: none;
}
.footer .copy {
  width: 100%;
  height: auto;
  clear: both;
  color: #686868;
  font-size: 12px;
}
.footer .cert-logo {
  width: 100%;
  height: auto;
  overflow: hidden;
  margin-top: 10px;
}
.footer .cert-logo .cert-logo-list {
  width: 73px;
  height: 30px;
  float: left;
  display: block;
  margin-right: 10px;
  overflow: hidden;
}
.footer .cert-logo .cert-logo-list img {
  width: 100%;
  height: 100%;
  border: 0px none;
}

.error-msg {
  position: absolute;
  top: 121%;
  left: 495px;
  color: red;
}
.error-msg {
  position: absolute;
  top: 103%;
  left: 8px;
  color: red;
}
</style>
